package com.hy.generator.api;

import com.hy.generator.common.exception.BusinessException;
import com.hy.generator.param.BuildParam;
import com.hy.generator.service.BuildService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/build")
public class BuildApi {

    @Autowired
    private BuildService buildService;

    @PostMapping()
    public void build(BuildParam buildParam, @RequestParam("file") MultipartFile[] files, HttpServletResponse response) {
        log.info("开始构建");
        try {
            buildService.build(buildParam, files, response);
        } catch (IOException e) {
            throw new BusinessException(e.getMessage());
        }
    }
}
